Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #217 - onboarding screenshot generation. #1529

Merged
merged 5 commits into from
Apr 11, 2022

Conversation

monsieurtanuki
Copy link
Contributor

New files:

  • app_test.dart: Onboarding screenshot generation.
  • screenshot_driver.dart: Screenshot driver.

Impacted files:

  • analytics_helper.dart: added a special case for screenshot init.
  • main.dart: refactored for screenshots, and more specifically moved init code to be run before calling the app.
  • next_button.dart: added a Key for test/screenshots
  • Podfile.lock: wtf
  • pubspec.lock: impacted by pubspec.yaml
  • pubspec.yaml: added integration_test and flutter_driver to dev_dependencies.

What

  • Screenshot generation for onboarding.
  • First screenshot generation of the app: it works but there's some fine-tuning to do, regarding initial data and bad FutureBuilder management by the test framework.
  • More info available in app_test.dart (how to star the screenshots) and screenshot_driver.dart (how to make that work in iOS)

Screenshot

test-screenshot-onboarding-eco

Part of

New files:
* `app_test.dart`: Onboarding screenshots.
* `screenshot_driver.dart`: Screenshot driver.

Impacted files:
* `analytics_helper.dart`: added a special case for screenshot init.
* `main.dart`: refactored for screenshots, and more specifically moved init code to be run before calling the app.
* `next_button.dart`: added a `Key` for test/screenshots
* `Podfile.lock`: wtf
* `pubspec.lock`: impacted by `pubspec.yaml`
* `pubspec.yaml`: added integration_test and flutter_driver to dev_dependencies.
@monsieurtanuki monsieurtanuki requested a review from a team as a code owner April 10, 2022 09:02
Impacted files:
* `pubspec.lock`: impacted by `pubspec.yaml`.
* `pubspec.yaml`: upgraded the version numbers.
@teolemon
Copy link
Member

That's awesome @monsieurtanuki
So, if I want to run this from #1208 , I would just need to run the integration tests ?
Classicaly, I built a modified version of the app + specific APKs (in the case of Android), and run a gradle command to launch generation

@monsieurtanuki
Copy link
Contributor Author

So, if I want to run this from #1208 , I would just need to run the integration tests ?

That's what you have to run:

flutter drive --driver=test_driver/screenshot_driver.dart --target=integration_test/app_test.dart

As is, that generates the screenshot files with hard-coded names in a new screenshots folder (same level as lib)
That means that there is definitely some customization to do, regarding:

  • the "root" folder for the screenshot files (so far, always the same)
  • the filenames themselves (so far, always the same filenames)
  • in order to make different names (language, country?, platform)
  • probably with ENV variables

@teolemon
Copy link
Member

also device size / models (especially for iOS)

Copy link
Member

@M123-dev M123-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heyyy thanks a lot @monsieurtanuki, automated screenshots ate definitely great. I actually have a stale integration tests branch it's a great opportunity to add further testing together with the screenshots. The majority looks good but please have a look at my comments.

Future<void> _initScreenshot(
final IntegrationTestWidgetsFlutterBinding binding,
) async {
if ((!kIsWeb) && Platform.isAndroid) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't be Web when it's android or am I missing something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, but I explicitly say that I handle the kIsWeb case - which wouldn't be obvious without that additional test. Or it would be a comment: I prefer code to comment.

if (!_screenshots) {
await _userPreferences.init(_productPreferences);
}
AnalyticsHelper.initMatomo(context, _screenshots);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just put it in the if statement above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I can't: I do things in AnalyticsHelper.initMatomo(context, _screenshots);.

Comment on lines 145 to 147
if (!_screenshots) {
FlutterNativeSplash.remove();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment why we what it looks like never remove the splash screen

await app.main(screenshots: true);
await tester.pumpAndSettle();

sleep(const Duration(seconds: 30));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think pumpAndSettle already takes care of waiting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of anything anymore. Especially when there's async load: ok the pumpAndSettle will tell you that the display is refreshed, but not that the data was loaded async'ly in order to refresh the display.

if (!_screenshots) {
await _userPreferences.init(_productPreferences);
}
AnalyticsHelper.initMatomo(context, _screenshots);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need _screenshots as argument as it's a global variable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is: it's private.

static void initMatomo(final BuildContext context) {
static void initMatomo(
final BuildContext context,
final bool screenshotMode,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this parameter as it's a global value

final bool screenshotMode,
) {
if (screenshotMode) {
setCrashReports(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about putting the same logic in initSentry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not that I particulary care about Matomo rather than Sentry; it's just that initMatomo froze the app in screenshot mode. And I'm sort of forced to call initMatomoso that the next matomo calls don't crash.
In screenshot mode I don't even call initSentry.

@M123-dev
Copy link
Member

info • Avoid print calls in production code • packages/smooth_app/test_driver/screenshot_driver.dart:27:5 • avoid_print

Impacted files:
* `main.dart`: added a comment.
* `screenshot_driver.dart`: removed a "forbidden" `print` statement.
@codecov-commenter
Copy link

Codecov Report

Merging #1529 (8fcb62a) into develop (342f8c0) will decrease coverage by 0.00%.
The diff coverage is 15.78%.

@@            Coverage Diff             @@
##           develop   #1529      +/-   ##
==========================================
- Coverage     8.90%   8.89%   -0.01%     
==========================================
  Files          161     161              
  Lines         6581    6596      +15     
==========================================
+ Hits           586     587       +1     
- Misses        5995    6009      +14     
Impacted Files Coverage Δ
...kages/smooth_app/lib/helpers/analytics_helper.dart 0.00% <0.00%> (ø)
packages/smooth_app/lib/main.dart 17.89% <14.70%> (-1.62%) ⬇️
...s/smooth_app/lib/pages/onboarding/next_button.dart 4.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 342f8c0...8fcb62a. Read the comment docs.

@monsieurtanuki monsieurtanuki requested a review from M123-dev April 10, 2022 19:09
@teolemon teolemon added this to the V1.1 milestone Apr 11, 2022
@M123-dev
Copy link
Member

@monsieurtanuki this whole analytics stuff looks a bit confusing to me, we call the initialization but return before the real call and first set the analytics to what is saved in the preferences then overwrite it when in screenshot mode. Instead of putting in the mock preferences, but let's not block it on this we can always improve that part later.

@monsieurtanuki monsieurtanuki merged commit e23117d into openfoodfacts:develop Apr 11, 2022
@monsieurtanuki
Copy link
Contributor Author

Thank you @M123-dev!
If you feel confused about this PR it's because I explained very well ;)
The screenshots are a mess and a pain in the neck. No logic involved. As I said before there are fine-tuning and refactoring to do, the tricky part being to always check that we've still got screenshots generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants